package com.swxy.club.utils;

import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;

/**
 * @author 易
 */
public class AesUtil {

    private static final String KEY = "ThisIsASecretKey";
    private static final String IV = "InitializationVe";

    /**
     * AES加密字符串
     *
     * @param data 要加密的数据
     * @return 加密后的Base64编码字符串
     */
    public static String encrypt(String data) {
        AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, KEY.getBytes(), IV.getBytes());
        return aes.encryptBase64(data);
    }

    /**
     * AES解密字符串
     *
     * @param encryptedData Base64编码的加密数据
     * @return 解密后的原始字符串
     */
    public static String decrypt(String encryptedData) {
        AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, KEY.getBytes(), IV.getBytes());
        return aes.decryptStr(encryptedData);
    }
}